package com.woniu.common;

import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel("接口请求结果")
public class DataInfo<T> extends BaseInfo {

    @ApiModelProperty(value = "结果集", position = 3)
    @JSONField(ordinal = 3)
    private T data;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> DataInfo<T> success(T t) {
        DataInfo<T> result = new DataInfo<>();
        result.setStatus(SUCCESS_CODE);
        result.setMessage(SUCCESS_MESSAGE);
        result.setData(t);
        return result;
    }

    public static <T> DataInfo<T> error(String message) {
        DataInfo<T> result = new DataInfo<>();
        result.setStatus(ERROR_CODE);
        result.setMessage(message);
        return result;
    }
}
